<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>数据管理条目列表</title>
	<%@ include file="/common/import.jsp" %>
	
	<script>
	var cateEname = '${cateEname}';
	$(function(){
			$('#dataItemList').datagrid({
				title:'列表['+cateEname+']',
				iconCls:'icon-ok',
				url:'${ctx }/dict/item/list!data.action?cateEname='+cateEname,
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[15,20,30,50],
				idField:'itemId',
				columns:[[
					{field:'itemText',title:'条目名称',width:100,sortable:true},
					{field:'itemValue',title:'条目值',width:100,sortable:true},
					{field:'itemStatus',title:'状态',width:50,sortable:true,
						formatter:function(value){
							if( value=='1'){return '<font color=blue>启用</font>';}
							else{ return '<font color=red>停用</font>';}
						}
					},
					{field:'itemRemark',title:'备注',width:100,sortable:true}
					
				]],
				toolbar:[{
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						saveItem();
					}
				}
				,'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteItem();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editItem();
					}
				},'-',{
					text:'查找',
					iconCls:'icon-search',
					handler:function(){
						$('#query').window('open');
						$('#itemText').focus();
					}
				}
				,'-',{
					text:'刷新',
					iconCls:'icon-reload',
					handler:function(){
						itemReload();
					}
				}
				
				]
			})
		});
		
		function itemReload(){
			$('#dataItemList').datagrid('reload');
		}
		
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		function saveItem(){
			
			$('#saveFrame').html('');			
			var url = '${ctx}/dict/item/add.action?cateEname='+cateEname;				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		function editItem(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/dict/item/edit.action?id='+node.itemId;
				$('#saveFrame').attr("title",node.itemText);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		function searchItem(){
			var queryParams = $('#dataItemList').datagrid('options').queryParams;	       
	        queryParams.itemText = $('#itemText').val();
	        queryParams.itemValue = $('#itemValue').val();
	        $('#dataItemList').datagrid("reload");
	        $('#query').window('close');
			
		}
				
		
		function getSelected(){
			var selected = $('#dataItemList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		function deleteItem(){					
			var node = getSelected();	
			
			if(node){
		       $.messager.confirm('确认','您确定要删除:<font color=red>'+node.itemText+'</font> ？',function(r){
		          if(r){
						$.ajax({
								type: "post",
								url: "${ctx}/dict/item/del.action?id="+node.itemId,
								success: function(data, textStatus){
									$.messager.alert('结果', '操作成功', 'info',function(){
										$('#dataItemList').treegrid('remove', node.itemId);
									});	
								},
								error: function(messg){
									$.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
								}
							});
		          }
		       });		             		
		    }	
		}
							
	</script>
</head>
<body>
		
	<table id="dataItemList"></table>	
	<div id="saveDiv" class="easyui-window" title="数据定义" style="padding:5px;width: 550px;height:400px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 <iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="yes" frameborder="0" ></iframe>
    </div>
    
        <!-- 查询窗口 -->
	<div id="query" class="easyui-window" title="查询" style="padding:5px;width:400px;height:250;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
	<table class="datagrid-body" >
		<tr >	
			<td class="datagrid-header">条目名称：</td>
			<td><input type="text" id="itemText" name="itemText" size="30" value="" /></td>
		</tr>
		
		<tr >
			<td class="datagrid-header">条目值：</td>
			<td><input type="text" id="itemValue" name="itemValue" size="30" value="" /></td>
		</tr>
		<!--
		<tr>
		<td class="datagrid-header">状态</td>
			<td>
			<input type="radio" name="itemStatus" id="itemStatus_1" value="1" />启用
			<input type="radio" name="itemStatus"  id="itemStatus_0" value="0" />停用
			</td>
		</tr>
		-->
		 <tr>	
			<td class="datagrid-header"></td>
			<td><a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="searchItem();">查找</a></td>	
		</tr>
	</table>
    </div>
</body>
</html>